#ifndef COMMONSTRUCT_H
#define COMMONSTRUCT_H

#define MAX_FEATHER_TYPE 2

#define MAX_COLOR_NUMBER        16
#define MAX_PASS_NUMBER         32
#define MAX_NOZZLE_NUMBER       256
#define MAX_NOZZLE_GROUP        8
#define MAX_GROUP_CHIP			2
#define MAX_PRINT_LINES         4
#define MAX_PRINT_MATERIAL      10
#define MAX_FEATHER_TYPE		2
#define MAX_DIRECTION           2 //X, Y
#define MAX_CLEAN_MODE			2
#define MAX_FLASH_MODE			3
#define MAX_CLEAN_INTERVAL_MODE 3
#define MAX_NOZZLEBOARD_NUMBER  2	//最大使用的喷头板数
#define MAX_INTERFACE_BOARD		2
#define MAX_NOZZLEBOARD_SLOT	4
#define MAX_INK_SEQUENCE		8
#define MAX_NOZZLE_COLOR		8	//一个喷头最大颜色数
#define MAX_NOZZLE_ROW			8	//喷头最大排数
#define MAX_NOZZLE_TYPE			3	//使用的喷头类型数
// 横向光栅物理精度可变
#define MAX_PRECISION_NUMBER    7 //180, 240, 360, 480, 720, 1080,1440
#define MAX_SPEED_NUMBER        3 //Hi,Mi,Lo
#define MAX_COLORBAR_NUMBER     3 //Hi,Mi,Lo
#define MAX_FLASHSTYLE_NUMBER   3 //Hi,Mi,Lo
#define BOOLEAN_MAX_NUMBER      2 //0,1
//光栅精度固定为720
#define RASTER_FIXED_DPI    720
//#define OUTPUT_INK_BIT          1
//#define ONE_FLASH_DATA_WIDTH    16 // 16为支持4个喷头, 32为支持8个喷头
//#define ONE_FLASH_DATA_SIZE     MAX_NOZZLE_NUMBER*(ONE_FLASH_DATA_WIDTH/8)*OUTPUT_INK_BIT
// once bulkwrite frame max num
#define FLASH_CACHE_DATA_LEN    (1024 * 2)
//#define FEATHER_MASK_WIDTH      512
//#define FEATHER_MASK_BYTESIZE   64  //(FEATHER_MASK_WIDTH/8)
#define FEATHER_MASK_LONGSIZE   128  //(FEATHER_MASK_WIDTH/32)
#define FRONT_BACK_PASS_NUMBER	3 //第一pass和最后两pass
#define ONE_GROUP_NOZZLES		2 //一组包含几个喷头
#define MAX_SENSOR_NUMBER	8	//板卡最大传感器个数
#define MAX_PRINT_MATERIAL      10

#include <QStringList>
#include "xpack/xpack.h"
#include <memory.h>
/**
 * @brief The CommonPrintSetPARAM struct 打印设置
 */
struct CommonPrintSetPARAM
{
    uint32_t PrintDirectionSelect;  //打印方向选择 0-双向打印 1-向左打印 2-向右打印
    uint32_t PrintSpeedSelect;      //打印速度选择 0-高速 1-中速 2-低速
    int bNozzleCrossPartUse;        //叠孔羽化使能
    int PrintFeatherEnable;         //pass羽化使能
    uint32_t PrintFeatherSelect;    //羽化模式选择 0-渐变羽化 1-均匀羽化
    uint8_t  PrintFeatherPercent[MAX_FEATHER_TYPE] ;   //羽化百分比 0~100 超出按100计算, 不同羽化使用不同百分比

    int      bFlashBeforePrint;         //打印前是否闪喷
    double   PaperWidth;            // 纸张宽度
    double   PrintStartPositionMM;  //打印起始位置

    int      bColorBarEnable;       // 彩条开关 0-关 1-开
    int      ColorBarSelect;        // 彩条选择  0-左彩条 1-右彩条 2-左右彩条
    double   ColorBarWidth;         // 单色彩条宽度 单位(mm)
    double   ColorBarGap;           // 彩条与图之间的间隙 单位(mm)
    int      ColorBarConcPercentage;// 彩条浓度 0~100

    uint32_t ColorBarstyleSelect ;//色条风格选择 0-只在有数据的地方打彩条 1-全程彩条
    int       InkMultiplier;      //多倍墨量数 0-不处理 1-不处理 2,3,4-倍墨量，>4 不处理
    int       bUseCutter;         //切纸 0-自动切纸 关 |  1-自动切纸 开

    CommonPrintSetPARAM()
    {
        PrintDirectionSelect=0;  //打印方向选择 0-双向打印 1-向左打印 2-向右打印
        PrintSpeedSelect=0;      //打印速度选择 0-高速 1-中速 2-低速
        bNozzleCrossPartUse=0;        //叠孔羽化使能
        PrintFeatherEnable=0;         //pass羽化使能
        PrintFeatherSelect=0;    //羽化模式选择 0-渐变羽化 1-均匀羽化
        bFlashBeforePrint=0;         //打印前是否闪喷

        for(int i=0;i<MAX_FEATHER_TYPE;i++){
            PrintFeatherPercent[i]=0;   //羽化百分比 0~100 超出按100计算, 不同羽化使用不同百分比
        }
        PaperWidth=0;            // 纸张宽度
        PrintStartPositionMM=0;  //打印起始位置
        bColorBarEnable=0;       // 彩条开关 0-关 1-开
        ColorBarSelect=0;        // 彩条选择  0-左彩条 1-右彩条 2-左右彩条
        ColorBarWidth=0;         // 单色彩条宽度 单位(mm)
        ColorBarGap=0;           // 彩条与图之间的间隙 单位(mm)
        ColorBarConcPercentage=0;// 彩条浓度 0~100
        ColorBarstyleSelect = 0;
        InkMultiplier = 0;
        bUseCutter = 0;

    }

    XPACK(O(PrintDirectionSelect,PrintSpeedSelect,bNozzleCrossPartUse,PrintFeatherEnable,
            PrintFeatherSelect,PrintFeatherPercent,bFlashBeforePrint,PaperWidth,PrintStartPositionMM,
            bColorBarEnable,ColorBarSelect,ColorBarWidth,ColorBarGap,ColorBarConcPercentage,
            ColorBarstyleSelect,InkMultiplier,bUseCutter));
};

/**********************************************************************/
/**
 * @brief The NozzleCalibrationPARAM struct 喷头校准
 */
struct QNozzleCalibrationPARAM
{
    uint32_t    printMaterialNumber = 0;  // 当前打印材料数
    QStringList printMaterialNames;       // 打印材料名称
    int         calibrationMaterial = 1;  // 校准选择的材料
    int         calibrationXDpi = 4;      // 校准选择的横向精度 0~7 对应(180, 240, 360, 480, 720, 1080,1440)
    int         calibrationSpeed = 0;     // 校准选择的速度
    int         calibrationDir = 0;       // 校准选择的方向
    double      calibrationPrintWidth = 594;  // 测试图宽幅

    int         nozzleType;
    uint32_t    machineGroupNumber = 1;    // 机器当前喷头组数
    uint32_t    machineColorNumber = 4;    // 机器当前颜色数
    int         oneGroupNozzleNumber = 2;  // 一组包含的喷头数
    int         oneNozzleColorNumber = 4;  // 一个喷头颜色数
    int         oneClolorPrintLines  =1;

    // 喷头废孔
    uint32_t invalidNozzleNumber[MAX_COLOR_NUMBER][MAX_NOZZLE_GROUP][BOOLEAN_MAX_NUMBER];
    // 横向组间距
    int horzGroupSpacing[BOOLEAN_MAX_NUMBER][MAX_PRECISION_NUMBER][MAX_SPEED_NUMBER][MAX_NOZZLE_GROUP][ONE_GROUP_NOZZLES] = { 0 };
    // 步进校准
    double vertMotorRate[MAX_PRINT_MATERIAL]; //步进校准齿轮比
    int stepCalibrationPoint[MAX_PRINT_MATERIAL][MAX_PASS_NUMBER][MAX_SPEED_NUMBER]; //不同pass数的步进校准值 按打印精度点算
    // 套色校准
    // 同色套色
    int phyNozzlePrintLinePos[BOOLEAN_MAX_NUMBER][MAX_PRECISION_NUMBER][MAX_COLOR_NUMBER][MAX_NOZZLE_GROUP][MAX_PRINT_LINES] = { 0 }; // 孔排位置
    // 基准套色
    int baseNozzleOffset[BOOLEAN_MAX_NUMBER][MAX_PRECISION_NUMBER][MAX_COLOR_NUMBER][MAX_NOZZLE_GROUP] = { 0 };
    // 组内套色
    int horzGroupsOffset[MAX_PRECISION_NUMBER][MAX_COLOR_NUMBER] = { 0 };//喷头组横向间隔 720Dpi点数
    int stepAdjustOffset[MAX_COLOR_NUMBER] = { 0 }; //纵向套色
    // 双向套色校正
    int doubleNozzleOffset[MAX_PRINT_MATERIAL][MAX_PRECISION_NUMBER][MAX_SPEED_NUMBER][MAX_COLOR_NUMBER][MAX_NOZZLE_GROUP] = { 0 };

    XPACK(O(printMaterialNumber,
        printMaterialNames,
        calibrationMaterial,
        calibrationXDpi,
        calibrationSpeed,
        calibrationDir,
        calibrationPrintWidth,
        nozzleType,
        machineGroupNumber,
        machineColorNumber,
        oneGroupNozzleNumber,
        oneNozzleColorNumber,
        oneClolorPrintLines,
        invalidNozzleNumber,
        horzGroupSpacing,
        vertMotorRate,
        stepCalibrationPoint,
        phyNozzlePrintLinePos,
        baseNozzleOffset,
        horzGroupsOffset,
        stepAdjustOffset,
        doubleNozzleOffset
    ));
};

/*******************************************************/
/**
 * @brief The NozzleCalibrationTestImagePARAM struct 喷头校准测试图
 */
struct NozzleCalibrationTestImagePARAM
{
    int printMaterial = 0;
    int printDpi = 720;         // 横向精度
    int printYDpi = 600;
    int printSpeed = 0;
    int printDir = 0;           // 打印方向 0-双向 1-单向向左 2-单向向右
    double printWidth = 594;
    int passDiv = 1;
    int passNum = 1;
    int setParam = 0;
    int adjustPixel = 1;
    int printTimeMs = 1000;
    QString fileName;
    int colorOrder;
    int bOffline = 0;
    int blockHeight;

    NozzleCalibrationTestImagePARAM(){
        printMaterial = 0;
        printDpi = 720;         // 横向精度
        printYDpi = 600;
        printSpeed = 0;
        printDir = 0;           // 打印方向 0-双向 1-单向向左 2-单向向右
        printWidth = 594;
        passDiv = 1;
        passNum = 1;
        setParam = 0;
        adjustPixel = 1;
        printTimeMs = 1000;
        QString fileName ="";
        colorOrder = 0;
        bOffline = 0;
        blockHeight = 30;
    };


    XPACK(O(printMaterial,
        printDpi,
        printYDpi,
        printSpeed,
        printDir,
        printWidth,
        passDiv,
        passNum,
        setParam,
        adjustPixel,
        printTimeMs,
        fileName,
        colorOrder,
        bOffline,
        blockHeight
    ));
};

struct TempBoardAllPARAM
{
    uint16_t frontHeatTemp;	//设置 前加热 温度限制(0~100℃)
    uint16_t middleHeatTemp;//设置 中加热 温度限制(0~100℃)
    uint16_t rearHeatTemp;	//设置 后加热 温度限制(0~100℃)
    uint16_t fanGear;		//设置 吸风档位 0~9档
    uint16_t lightState;	//设置 灯带开关 0/1

    uint16_t realFrontHeatTemp;	//实时获取 前加热 温度
    uint16_t realMiddleHeatTemp;//实时获取 中加热 温度
    uint16_t realRearHeatTemp;	//实时获取 后加热 温度
    uint16_t realFanGear;		//实时获取 吸风档位 0~9档
    uint16_t realLightState;	//实时获取 灯带开关 0/1

    TempBoardAllPARAM& operator=(const TempBoardAllPARAM& other)
    {
        if (this != &other)
        {
            this->frontHeatTemp = other.frontHeatTemp;
            this->middleHeatTemp = other.middleHeatTemp;
            this->rearHeatTemp = other.rearHeatTemp;
            this->fanGear = other.fanGear;
            this->lightState = other.lightState;
            this->realFrontHeatTemp = other.realFrontHeatTemp;
            this->realMiddleHeatTemp = other.realMiddleHeatTemp;
            this->realRearHeatTemp = other.realRearHeatTemp;
            this->realFanGear = other.realFanGear;
            this->realLightState = other.realLightState;
        }
        return *this;
   }
};
XPACK_OUT(TempBoardAllPARAM,
          O(frontHeatTemp,middleHeatTemp,
            rearHeatTemp, fanGear,
            lightState, realFrontHeatTemp,
            realMiddleHeatTemp, realRearHeatTemp,
            realFanGear, realLightState));

// 单块台板参数
struct PlatformSetPARAM
{
    char  platName[0x20] = {0}; //台板名称
    float width = 0;  //台板宽 单位(mm)
    float height = 0; //台板高 单位(mm)
    float xPos = 0;   //台板x轴位置
    float yPos = 0;   //台板y轴位置
    PlatformSetPARAM& operator=(const PlatformSetPARAM& other)
    {
        if (this != &other)
        {
            memcpy(this->platName, other.platName, sizeof(this->platName));
            this->width = other.width;
            this->height = other.height;
            this->xPos = other.xPos;
            this->yPos = other.yPos;
        }
        return *this;
    }
//#ifdef XPACK
    XPACK(O(platName, width, height, xPos, yPos))
//#endif // XPACK
};

#define MAX_PLATFORM_NUMBER 5   //最大台板使用数

//多块台板参数
struct PlatformsPARAM
{
    bool        bUsePlatform = false;
    float       platformOrgToPrintDistance = 100;  //台板原点到打印位置的距离 单位(mm)
    //台板幅面以及台板xy距离设置
    int         platformNum = 5;          //设置的台板数
    int         platformUseIndex = 0;     //当前使用的台板
    PlatformSetPARAM platformsSetParam[MAX_PLATFORM_NUMBER]; //台板参数
    PlatformsPARAM& operator=(const PlatformsPARAM& other)
    {
        if (this != &other)
        {
            this->bUsePlatform = other.bUsePlatform;
            this->platformOrgToPrintDistance = other.platformOrgToPrintDistance;
            this->platformNum = other.platformNum;
            this->platformUseIndex = other.platformUseIndex;
            for (int i = 0; i < MAX_PLATFORM_NUMBER; ++i)
            {
                this->platformsSetParam[i] = other.platformsSetParam[i];
            }
        }
        return *this;
    }
//#ifdef XPACK
    XPACK(O(bUsePlatform, platformOrgToPrintDistance,platformNum,platformUseIndex,platformsSetParam))
//#endif // XPACK
};
#endif // COMMONSTRUCT_H
